import { GModalButton, GTree } from 'geminis-react';
import { useCallback, useRef } from 'react';

export const OrgSelectModal = (props: {
  text: string,
  onOk: (selection: any) => void
}) => {
  const tree = useRef<any>();

  const onOk = useCallback(() => {
    props.onOk?.(tree.current.selection);
  }, []);

  return (
    <GModalButton
      text={props.text}
      button={{
        type: 'link',
      }}
      onOk={onOk}
    >
      <GTree
        ref={tree}
        url="/api/resources/organization/children/"
        {...props}
      />
    </GModalButton>

  );
};
